#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <arc4.h>
#include "arc4_codec.h"

using namespace CryptoPP;
using namespace CryptoPP::Weak;

class Arc4CodecImp
{
	ARC4 codec_;
public:
	Arc4CodecImp(scoped_array<unsigned char>& key)
	{
		codec_.SetKey((const byte*)key.get(), key.size());
	}

	inline void process(const scoped_array<char>& src, scoped_array<char>& dest)
	{
		if(dest.size() < src.size())
		{
			dest.reset(new char[src.size()], src.size());
		}
		codec_.ProcessData((byte*)dest.get(), (const byte*)src.get(), src.size());
	}
};

Arc4Codec::Arc4Codec(scoped_array<unsigned char>& key) : imp_(new Arc4CodecImp(key))
{
}

void Arc4Codec::process(const scoped_array<char>& src, scoped_array<char>& dest)
{
	imp_->process(src, dest);
}